package com.example.chatweb.controller;

import com.alibaba.fastjson2.JSON;
import com.example.chatweb.entity.ErnieBotTurboResponse;
import com.example.chatweb.entity.ErnieBotTurboStreamParam;
import com.example.chatweb.service.ErnieBotService;
import com.example.chatweb.utils.ErnieBotSourceListener;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ErnieBotController {
    @Resource
    private ErnieBotService ernieBotService;

    @RequestMapping("/erniebot")
    public String ernieBot(@RequestBody String message) {
        ernieBotService.BaiduService();
        ErnieBotTurboStreamParam question = JSON.parseObject(message, ErnieBotTurboStreamParam.class);
        ErnieBotTurboResponse ernieBotTurboResponse = ernieBotService.ernieBotTurbo(question);
        return ernieBotTurboResponse.getResult();
    }
    @RequestMapping("/erniebot-stream")
    public void ernieBotStream(@RequestBody String message) {
        ernieBotService.BaiduService();
        ErnieBotTurboStreamParam question = JSON.parseObject(message, ErnieBotTurboStreamParam.class);
        ernieBotService.ernieBotTurboStream(question,new ErnieBotSourceListener());
    }
}
